Arduino meets MATLAB: Interfacing, Programs and Simulink by Singh Rajesh & Gehlot Anita & Singh Bhupendra & Choudhury Sushabhan

Arduino meets MATLAB: Interfacing, Programs and Simulink by Singh Rajesh & Gehlot Anita & Singh Bhupendra & Choudhury Sushabhan

Author:Singh, Rajesh & Gehlot, Anita & Singh, Bhupendra & Choudhury, Sushabhan [Singh, Rajesh]
Language: eng
Format: azw3
ISBN: 9781681087283
Publisher: Bentham Science Publishers
Published: 2018-09-25T16:00:00+00:00


Fig. (5.11) shows circuit diagram for the interfacing of servo motor with Arduino.

Fig. (5.11))

Circuit diagram for the interfacing of servo motor with Arduino.

5.4.2. Program

#include <LiquidCrystal.h>

#include <Servo.h>

// initialize the library of LCD RS,E,D4,D5,D6,D7

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

Servo myservo; // create servo object to control a servo

// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()

{

lcd.begin(16, 2);// initialize the LCD

myservo.attach(3); // connect servo at pin3

}

void loop()

{

for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees(step of one degree)

{

lcd.clear();

myservo.write(pos); // tell servo to go to position in variable 'pos'

lcd.print(pos);// display position on LCD

delay(15); // delay 15ms

}

for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees

{

lcd.clear();

myservo.write(pos); // tell servo to go to position in variable 'pos'

lcd.print(pos);// display position on LCD

delay(15); // delay 15ms

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.